<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>Demo</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="handlerSubmitForm">保存</el-button>
                </div>
                <div >
                   <el-form  :rules="rules"  ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                          <el-col :span="12">
                              <el-form-item  label="分类名称"  prop="fdName">
                                  <el-input class="input" v-model="form.fdName" ></el-input>
                              </el-form-item>
                          </el-col>
                          <el-col :span="12">
                              <el-form-item  label="所属分类"  prop="fdParentName">
                                <select-tree
                                    :props="props"
                                    :action="url"
                                    v-model="form.fdParentName"
                                    :id.sync="form.fdParentId"
                                    />
                              </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="12">
                              <el-form-item  label="排序号"  prop="fdOrder">
                                  <el-input-number v-model="form.fdOrder" :min="0" ></el-input-number>
                              </el-form-item>
                          </el-col>
                        </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import selectTree from "@/components/form/FancySelectTree";
import formUtils from '@/utils/formUtils';
import {edit} from '@/components/mixins/form'
export default {
    name: "sysPermissionRoleCategoryAdd",
    components: {
        selectTree
    },
    data() {
        return {
            updateUrl:'/api/sys/permission/sys_permission_role_category',
            fetchUrl:'/api/sys/permission/sys_permission_role_category',
            form: {
                fdParentId:'',
                fdOrder:'',
                fdParentName:'',
                fdName:'',
                fdId:'',
                fdCreateTime:''
            },
            rules:{
                fdName :[{required: true, message: '请输入分类名称', trigger: 'blur'}]
            },
            props: {
                label: "name",
                value: "id",
            },
            url:"/sys/permission/sys_permission_role_category/treeData"
        }
    },
    mixins:[edit],
    mounted() {
        this.initParent();
    },
    methods: {
        initParent(){
            let fdParentId = this.$route.query.fdParentId;
            if(formUtils.isNotEmpty(fdParentId)){
              this.$fetch(this.fetchUrl,{
                    id:fdParentId
                }).then((res) => {
                    this.form.fdParentId = res.data.fdId;
                    this.form.fdParentName = res.data.fdName;
                });
            }
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>